/**
 * mocks测试数据
 * @author xiufu.wang
 */
const { createResonseSuccess } = require('./util')
const prettier = require('prettier')
//获取数据库列表
exports.findDbs = function (req, res) {
    res.json(createResonseSuccess(null, [
        { code: 'schema-1', label: 'schema-1' },
        { code: 'schema-2', label: 'schema-2' },
        { code: 'schema-3', label: 'schema-3' },
        { code: 'schema-4', label: 'schema-4' },
        { code: 'schema-5', label: 'schema-5' },
    ]))
}

//根据数据库获取表
exports.findTablesByDb = function (req, res) {
    const { data } = req.body || {}
    if (!data || !data.schema) {
        res.json(createResonseSuccess(null, []))
        return
    }
    res.json(createResonseSuccess(null, [
        { code: data.schema + '-table-1', label: data.schema + '-table-1' },
        { code: data.schema + '-table-2', label: data.schema + '-table-2' },
        { code: data.schema + '-table-3', label: data.schema + '-table-3' },
        { code: data.schema + '-table-4', label: data.schema + '-table-4' },
        { code: data.schema + '-table-5', label: data.schema + '-table-5' },
        { code: data.schema + '-table-6', label: data.schema + '-table-6' },
        { code: data.schema + '-table-7', label: data.schema + '-table-7' },
        { code: data.schema + '-table-8', label: data.schema + '-table-8' },
        { code: data.schema + '-table-9', label: data.schema + '-table-9' },
        { code: data.schema + '-table-10', label: data.schema + '-table-10' },
    ]))
}

//获取表列信息
exports.findTableColumns = function (req, res) {
    const { data } = req.body || {}
    if (!data || !data.table) {
        res.json(createResonseSuccess(null, []))
        return
    }
    res.json(createResonseSuccess(null, [
        { code: data.table + '-column-1', label: data.table + '-column-1' },
        { code: data.table + '-column-2', label: data.table + '-column-2' },
        { code: data.table + '-column-3', label: data.table + '-column-3' },
        { code: data.table + '-column-4', label: data.table + '-column-4' },
        { code: data.table + '-column-5', label: data.table + '-column-5' },
        { code: data.table + '-column-6', label: data.table + '-column-6' },
        { code: data.table + '-column-7', label: data.table + '-column-7' },
        { code: data.table + '-column-8', label: data.table + '-column-8' },
        { code: data.table + '-column-9', label: data.table + '-column-9' },
        { code: data.table + '-column-10', label: data.table + '-column-10' },
    ]))
}

//测试swagger 1
exports.getSwaggerApi1 = function (req, res) {
    res.json(createResonseSuccess(null, {
        schema: {
            requrest: {
                name: { type: 'string' },
                sex: { type: 'number', dict: 'SEX' }
            },
            response: {
                name: { type: 'string' },
                sex: { type: 'number', dict: 'SEX' },
                age: { type: 'number' }
            }
        }
    }))
}

//测试swagger 2
exports.getSwaggerApi2 = function (req, res) {
    res.json(createResonseSuccess(null, {
        schema: {
            requrest: {
                proname: { type: 'string' },
                count: { type: 'number' }
            },
            response: {
                proname: { type: 'string' },
                count: { type: 'number' },
                price: { type: 'number' }
            }
        }
    }))
}

exports.formatCode = function (req, res) {
    const code = req.body.code
    const formatCode = prettier.format(`
    const formatCode = ${code}
    `)
    res.json({
        formatCode: formatCode.substring(formatCode.indexOf('{'))
    })
}

exports.baseRouterUrl = '/mock/api/code-gen/user-mock/'
